package cn.shop.cloud.common;


import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * @program: work
 * @ClassName Result
 * @description: 后续启动器中的所有的方法的返回值都是 这个
 * @author: 李尧坤
 * @create: 2024−12-19 11:32
 * @Version 1.0
 **/

public class Result<T> {

    /**
     *    code : 200    500000000102
     *    Msg:  okle
     *    data 对象  集合  String  拆箱 装箱 操作 !!
     *
     *
     */

    private Integer code;//code码
    private String msg;//信息
    private T data;//数据


    public static  final int SUCCESS_CODE=200;
    public static  final String SUCCESS_MESSAGE="操作成功";

    public static  final int ERROR_CODE=500000;
    public static  final String ERROR_MESSAGE="系统异常";


    public static  <T> Result<T> success(T data){
        return  new Result<>(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }

    public static  <T> Result<T> success(String msg,T data){
        return  new Result<>(SUCCESS_CODE,msg,data);
    }


    public static  <T> Result<T> error(CodeMsg codeMsg){
        return  new Result<>(codeMsg.getCode(),codeMsg.getMsg(),null);
    }

    public static  <T> Result<T> defaultError(){
        return  new Result<>(ERROR_CODE,ERROR_MESSAGE,null);
    }

    public boolean hasError(){
        return this.code!=SUCCESS_CODE;
    }


    public Result() {
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
